<?php

Yii::import('ext.snauth.Auth');

class SNAuth extends CApplicationComponent
{
    public $service;
    public $services;

    public function getLinks($route)
    {
        Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/protected/extensions/snauth/javascript/SNAuthScript.js',CClientScript::POS_HEAD);
        $links='';
        foreach($this->services as $name=>$service){
            $service=$this->getService($name);
            $links.=$service->getImgLink($route);
        }
        return $links;
    }

    public function getService($serviceName)
    {
        if(!isset($this->services[strtolower($serviceName)])) return false;

        $class=$this->services[strtolower($serviceName)];
        $className=Yii::import($class['class']);

        $service=new $className();
        $service->clientId=isset($class['clientId']) ? $class['clientId'] : false;
        $service->clientSecret=isset($class['clientSecret']) ? $class['clientSecret'] : false;
        if(isset($class['clientPublic'])) $service->clientPublic=$class['clientPublic'];

        return $service;
    }
}